fix: implement missing utilities and fix edge-case bugs (all tests passing) - #275
Open
stooit wants to merge 1 commit into
Open
fix: implement missing utilities and fix edge-case bugs (all tests passing)#275stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
…ests Fixes 16 failing tests across the library: - calculator: divide now throws on division by zero - string-utils: wordCount collapses consecutive whitespace; implement truncate (word-boundary aware, ellipsis counts toward maxLength) - task-manager: implement remove, update (per-field guards), and sortBy (priority/status rank, createdAt oldest-first) - date-utils: fix off-by-one in formatRelative day rounding (36h -> 2 days) - validator: isEmail accepts multi-level subdomains and long TLDs; isUrl accepts hosts with explicit ports No test files modified; no new dependencies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes the full test suite pass — 60 pass, 0 fail (was 44 pass / 16 fail). No test files were modified and no dependencies were added.
Fixes by file
dividenow throwsError("Division by zero")when the divisor is0instead of returningInfinity/NaN.wordCounttrims and splits on\s+, so leading/trailing/consecutive whitespace no longer inflates the count.truncate(was a not-implemented TODO): returns the string unchanged whenlength <= maxLength; otherwise cuts at the last word boundary and appends"...", with the ellipsis counting towardmaxLength.remove(returnsfalsefor unknown ids),update(per-fieldundefinedguards so only supplied fields change;falsefor unknown ids), andsortBy(priority high→medium→low, status rank, andcreatedAtascending / oldest-first).formatRelativeday calculation (Math.floor→ rounded absolute hours), so exactly 36 hours reports "2 days ago" rather than "1 day ago".isEmailaccepts arbitrary subdomain depth and 2+ char TLDs (e.g..museum);isUrlaccepts hosts with explicit ports (e.g.http://localhost:3000), still restricted tohttp:/https:.Verification
bun test->60 pass, 0 failacross 5 files.tsc --noEmitclean.Assumptions & notes
isUrlnow accepts any host including internal addresses (localhost, link-local). If this validator is ever used to gate a server-side fetch, it would need an explicit host/IP allowlist to avoid becoming an SSRF vector.isEmailremains a syntax check only, not input sanitisation.